package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.MaterialWarehouseEntity
import com.c.ctgproject.ui.collect.MaterialCheckActivity
import com.c.ctgproject.ui.collect.MaterialHistoryActivity
import com.c.ctgproject.ui.collect.MaterialWarehouseOutSubmitActivity
import com.c.ctgproject.utils.MyConstants
import com.c.ctgproject.utils.noDataHandler
import org.jetbrains.anko.startActivity

class MaterialWarehouseAdapter(private val context: Context, private val mList: List<MaterialWarehouseEntity.DataBean>) : BaseEmptyRecyclerViewAdapterV2(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_material_warehouse_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            "重量KG: ${data.stockWeight.noDataHandler()}".also { holder.mWeightTV.text = it }
            holder.mCK.setOnClickListener {
                //出库
                context.startActivity<MaterialWarehouseOutSubmitActivity>(MyConstants.ID to data.stockId)

            }


            holder.mPD.setOnClickListener {
                //盘点
                context.startActivity<MaterialCheckActivity>(
                    MyConstants.ID to data.stockId,
                    MyConstants.WEIGHT to data.stockWeight,

                    )

            }
            holder.mLS.setOnClickListener {
                //历史
                context.startActivity<MaterialHistoryActivity>(MyConstants.ID to data.stockId)
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mWeightTV: TextView = view.findViewById(R.id.mWeightTV)
        val mCK: Button = view.findViewById(R.id.mCK)
        val mPD: Button = view.findViewById(R.id.mPD)
        val mLS: Button = view.findViewById(R.id.mLS)
    }


}